home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Video
/
World of Video.iso
/
datafiles
/
gfx_formats
/
gif
/
gif2.std
< prev
next >
Wrap
Text File
|
1995-02-13
|
43KB
|
1,268 lines
G I F (tm)
Graphics Interchange Format (tm)
A standard for the
storage and transmission
of raster-based graphics information
* * * * PRELIMINARY REVIEW DRAFT * * * *
Software Version 87a
Document Revision 1.0
May 1988
(c) 1987, 1988 by CompuServe Incorporated
All rights reserved
"GIF" and "Graphics Interchange Format" are trademarks of
CompuServe Incorporated,
an H&R Block Company
5000 Arlington Centre Blvd.
Columbus, Ohio 43220
(614) 457-8600
Disclaimer
This document contains the latest information available at the time of
its creation. However, CompuServe reserves the right to modify the
services described herein at any time, with or without written
notification.
i
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii
1.0 Introduction to GIF . . . . . . . . . . . . . . . . . . . . . 1
1.1 Changes to GIF . . . . . . . . . . . . . . . . . . . . . 2
1.2 Availability of GIF . . . . . . . . . . . . . . . . . . . 3
1.3 Naming Files which Contain GIF Data . . . . . . . . . . . 4
1.4 GIF Development Area . . . . . . . . . . . . . . . . . . 5
2.0 Format of GIF Data . . . . . . . . . . . . . . . . . . . . . . 6
2.1 Signature/Version Block . . . . . . . . . . . . . . . . . 8
2.2 Logical Screen Descriptor Block . . . . . . . . . . . . . 10
2.3 Global Color Map Block . . . . . . . . . . . . . . . . . 14
2.4 Extension Block . . . . . . . . . . . . . . . . . . . . . 16
2.4.1 Comment Extension Block . . . . . . . . . . . . . 18
2.4.2 Image Control Extension Block . . . . . . . . . . 20
2.5 Image Descriptor Block . . . . . . . . . . . . . . . . . 23
2.5.1 Interlaced Image Processing . . . . . . . . . . . 27
2.6 Local Color Map Block . . . . . . . . . . . . . . . . . . 29
2.7 Raster Data Block . . . . . . . . . . . . . . . . . . . . 30
2.8 Terminator Block . . . . . . . . . . . . . . . . . . . . 32
3.0 Encoding and Decoding . . . . . . . . . . . . . . . . . . . . 33
3.1 Compressing and Expanding Pixel Data . . . . . . . . . . 35
3.2 Byte Packaging . . . . . . . . . . . . . . . . . . . . . 37
3.3 Display Rendering . . . . . . . . . . . . . . . . . . . . 38
4.0 Transmitting and Displaying GIF Data . . . . . . . . . . . . . 39
4.1 GIF Enquiry Escape Sequence and Response . . . . . . . . 40
4.2 GIF Invocation Escape Sequences . . . . . . . . . . . . . 45
4.3 Terminating Display of an Image . . . . . . . . . . . . . 46
4.4 User Interface to Decoders . . . . . . . . . . . . . . . 47
Appendix: Compression and Expansion Algorithm . . . . . . . . . A-1
GIF Revision 1.0, 5/88
ii
Preface
------------------------------------------------------------------------
------------------------------------------------------------------------
Objectives The objectives of this document are to:
. describe the Graphics Interchange Format (GIF)
. describe encoding and decoding
. provide guidelines for application programs which
transmit and display GIF data
The document describes version 87a of GIF.
--------------------------------------------------------
Intended The intended audience of this document is graphics
audience programmers who write application programs which use GIF
data.
--------------------------------------------------------
Organization A table of contents is provided to aid in locating
specific information within the document.
The document contains an introduction to GIF which is
followed by detailed information about GIF. This
detailed information is divided into three sections:
. Format of GIF data
. Encoding and decoding
. Transmitting and displaying GIF data
The compression and expansion algorithm applied to pixel
data is included in the Appendix at the end of the
document.
--------------------------------------------------------
Conventions The following conventions are used in this document:
. all numbers are decimal unless otherwise indicated
. a hexadecimal number is immediately followed by a
lowercase "h"
Examples: 0h, 2Ch, FFh, A014h
--------------------------------------------------------
(continued)
GIF Revision 1.0, 5/88
iii
Preface, continued
------------------------------------------------------------------------
------------------------------------------------------------------------
Conventions . exponentiation is represented in the standard
(continued) mathematical superscripted fashion
(n+1)
Example: 2 to the (n+1) power is shown as 2
. bits within a byte are numbered from right to left,
starting with 0; bit 0 is the least significant bit
and bit 7 is the most significant bit
. American Standard Code for Information Interchange
(ASCII) character codes are often listed in
parentheses after special characters (for example,
^) and character sequences which must be entered
exactly as shown; this is done, in part, to avoid
confusion when the document is transmitted
electronically and special characters in the
resulting file do not appear as they did in the
original document
--------------------------------------------------------
GIF Revision 1.0, 5/88
1
1.0 Introduction to GIF
------------------------------------------------------------------------
------------------------------------------------------------------------
What is GIF? GIF is the acronym for Graphics Interchange Format. GIF
is a format which is used to store and transmit raster-
based color and monochrome images in an efficient,
hardware-independent manner.
--------------------------------------------------------
History of GIF GIF was developed by CompuServe Incorporated to address
the need for a general color image definition and to
facilitate the exchange of images between dissimilar
computer hardware.
--------------------------------------------------------
Features To encourage its use in a wide variety of applications,
an explicit design goal of GIF is to provide a flexible
and comprehensive set of features. These features
include:
. arbitrary image dimensions up to 64K pixels
. as many as 256 colors in a given image
. image colors chosen from a palette of over 16
million colors
. hardware-independent format
. reduced file sizes by use of advanced data
compression techniques
. efficient decoding method which allows online
viewing of images via networks
. hardware-independent format not as efficient as a
hardware-specific format
. transmission of GIF data requires full 8-bit
transmission capability
. follows raster-based, as opposed to object-based,
graphics philosophy
. quality of image display subject to limitations of
display hardware
--------------------------------------------------------
GIF Revision 1.0, 5/88
2
1.1 Changes to GIF
------------------------------------------------------------------------
------------------------------------------------------------------------
Controlling Changes to the GIF definition are under the control of
changes CompuServe and will remain so until GIF is proposed or
adopted as an official industry standard. Changes are
expected every 12-18 months to address the needs of the
evolving graphics marketplace.
--------------------------------------------------------
User Users are discouraged from making ad hoc changes to the
enhancements GIF definition, not only to avoid the "multiple-variant"
syndrome other public domain computer standards suffer
from, but also to keep in the spirit of machine and
application independence central to the GIF effort.
--------------------------------------------------------
Proposing Users are encouraged to submit their proposals for
changes changes to the GIF definition. Each proposal should
outline the change and the reasoning behind it.
Proposals may be submitted via U.S. mail to:
Manager of Graphics Technology
CompuServe Incorporated
5000 Arlington Centre Boulevard
Columbus, Ohio 43220
Proposals may also be submitted in the GIF development
area of the CompuServe Information Service (CIS) (see
section 1.4, page 5).
--------------------------------------------------------
GIF Revision 1.0, 5/88
3
1.2 Availability of GIF
------------------------------------------------------------------------
------------------------------------------------------------------------
Availability GIF is available for use in any application program
of GIF without royalties or licensing restrictions. CompuServe
does ask, however, that any such program include a
trademark statement attributing ownership of GIF to
CompuServe Incorporated.
--------------------------------------------------------
Support for GIF support is available in the GIF development area of
GIF the CompuServe Information Service (CIS) (see section
1.4, page 5).
--------------------------------------------------------
GIF Revision 1.0, 5/88
4
1.3 Naming Files which Contain GIF Data
------------------------------------------------------------------------
------------------------------------------------------------------------
Overview Guidelines for naming files which contain GIF data are
provided in this section. Use of these guidelines is
suggested; however, their use is not necessary for
conformance with the GIF standard.
--------------------------------------------------------
In MS-DOS and Use ".GIF" as the extension for a file which contains
similar GIF data when in MS-DOS or a similar operating system.
operating
systems
--------------------------------------------------------
With the Apple Classify a file which contains GIF data as type "GIFf"
Macintosh when using software for the Apple Macintosh which reads
or writes such files. Doing this helps to prevent
problems when using communications programs to transfer
files.
No official GIF icon has been defined to represent files
which contain GIF data. Any icon used to represent such
files should include the characters "GIF".
--------------------------------------------------------
With other When naming files which contain GIF data, use a unique
operating and consistent file identification within the structure
systems of the local file identification conventions.
--------------------------------------------------------
GIF Revision 1.0, 5/88
5
1.4 GIF Development Area
------------------------------------------------------------------------
------------------------------------------------------------------------
What is the The GIF development area is an area within the
GIF CompuServe Information Service (CIS) where CompuServe
development provides GIF support and incentives for its use by
area? independent software developers. The GIF development
area is located in the Pictures Support Forum.
--------------------------------------------------------
Benefits of Benefits of joining the GIF development area include:
joining the
area . free access to the area
. access to GIF source code modules
. access to GIF utilities and working programs
. support from CompuServe associates
. support from other GIF developers
. periodic electronic conferences with CompuServe
associates and other GIF developers
--------------------------------------------------------
Requirements Members of the GIF development area must:
. be CIS subscribers
. adhere to the published GIF standard
. include, in any application program developed using
GIF, a trademark statement attributing ownership of
GIF to CompuServe Incorporated
--------------------------------------------------------
How to join To become a member of the GIF development area:
1. Access the Pictures Support Forum (direct access
may be obtained by typing the CIS command "GO
PICS").
2. Join the Pictures Support Forum by following the
instructions provided in that forum.
3. Enter library 1 of the Pictures Support Forum
(General/Utilities).
4. Read the file "DEVGIF.TXT" and follow its
instructions for joining the GIF development area.
Once your application has been approved, access will be
granted to the GIF development area.
--------------------------------------------------------
GIF Revision 1.0, 5/88
6
2.0 Format of GIF Data
------------------------------------------------------------------------
------------------------------------------------------------------------
Overview On a display surface, an image is a rectangular array of
pixels. This pixel array may be stored in a file as a
series of pixels. GIF defines a format for storing
pixels and the information needed to interpret and
display the pixels.
A file may be comprised entirely of GIF data;
conversely, GIF data may be one component of a much
larger file.
--------------------------------------------------------
Pixels With GIF, an image is stored as a series of pixels.
These pixels serve as index values into a color map.
The color map defines the color assigned to each pixel.
Pixels are stored without any indication of position
within the image.
--------------------------------------------------------
Color maps A color map is a series of red, green, and blue
intensity values that defines the individual colors
which may appear in an image. Pixels serve as index
values into the color map.
GIF data may include a global color map; this global
map is used for each image when no local color map is
associated with the image. A local color map is a
color map that is used for only one image. When no
global or local color map is present, pixels cannot be
mapped to color definitions, and interpretation of
pixels is indeterminate.
--------------------------------------------------------
Format of GIF GIF data is comprised of functional data blocks, some of
data which may be repeated, others of which are optional.
These blocks are shown on the following page and are
described in detail in the following sections.
--------------------------------------------------------
(continued)
GIF Revision 1.0, 5/88
7
2.0 Format of GIF Data, continued
------------------------------------------------------------------------
------------------------------------------------------------------------
Format of GIF GIF Data
data
(continued) +---------------------------------+
| Signature/Version Block |
+---------------------------------+ -+
| Logical Screen Descriptor Block | | Logical Screen
+---------------------------------+ | Block
|Global Color Map Block (optional)| |
+---------------------------------+ -+
| Extension Block (optional) | -- may be repeated
+---------------------------------+ -+
| Image Descriptor Block | |
+---------------------------------+ | Image Block;
|Local Color Map Block (optional) | | may be repeated
+---------------------------------+ |
| Raster Data Block(s) | |
+---------------------------------+ -+
| Extension Block (optional) | -- may be repeated
+---------------------------------+
| Terminator Block |
+---------------------------------+
--------------------------------------------------------
Data types Data type refers to the structure of a data segment and
determines how that data segment is interpreted. The
data types used in GIF data are:
+---------+--------------------------------------------+
|Data Type| Description |
+---------+--------------------------------------------+
|byte |8-bit unsigned value; may represent charac- |
| |ters or numeric values between 0 and 255 |
+---------+--------------------------------------------+
|field |2 to 7 contiguous bits within a given byte; |
| |interpretation depends on the quantity |
| |represented |
+---------+--------------------------------------------+
|flag |1-bit value which represents a logical true |
| |(1) or false (0) |
+---------+--------------------------------------------+
|integer |16-bit unsigned integer value; always stored|
| |least significant byte first |
+---------+--------------------------------------------+
--------------------------------------------------------
GIF Revision 1.0, 5/88
8
2.1 Signature/Version Block
------------------------------------------------------------------------
------------------------------------------------------------------------
Overview The Signature/Version Block:
. identifies a block of data as GIF data
. indicates the version of GIF used to define the
data
--------------------------------------------------------
Use of the Decoding software may use the Signature/Version Block to
Signature/ determine the version of GIF used to define the data.
Version Block This information may be needed by the decoding software
to determine if it is able to process the data; if the
decoding software was built from a version of GIF which
is older than that used to define the data, the
decoding software may not be able to adequately support
features of the newer definition.
--------------------------------------------------------
Existence The Signature/Version Block is required. It must be the
first block in the GIF data.
--------------------------------------------------------
Size The Signature/Version Block is six bytes long.
--------------------------------------------------------
Structure of The structure of the Signature/Version Block is
the Signature/ illustrated below.
Version Block
Bits
7 6 5 4 3 2 1 0 Byte #
+---+---+---+---+---+---+---+---+
| | 1
+- -+
| Signature | 2
+- -+
| | 3
+-------------------------------+
| | 4
+- -+
| Version | 5
+- -+
| | 6
+-------------------------------+
--------------------------------------------------------
(continued)
GIF Revision 1.0, 5/88
9
2.1 Signature/Version Block, continued
------------------------------------------------------------------------
------------------------------------------------------------------------
Structure of where:
the
Signature/ +------------+-------+---------------------------------+
Version Block | Item | Data | Description |
(continued) | | Type | |
+------------+-------+---------------------------------+
|Signature |bytes |ASCII text characters "GIF" |
| | |(47h 49h 46h); identifies the |
| | |block as GIF data |
+------------+-------+---------------------------------+
|Version |bytes |3-byte string of ASCII characters|
| | |which identifies the version of |
| | |GIF used to define the data; the |
| | |first two characters are the |
| | |year of the definition and the |
| | |last character is the lowercase |
| | |alphabetic version sequence |
| | |number; the current version |
| | |is 87a (38h 37h 61h) |
+------------+-------+---------------------------------+
--------------------------------------------------------
GIF Revision 1.0, 5/88
10
2.2 Logical Screen Descriptor Block
------------------------------------------------------------------------
------------------------------------------------------------------------
Overview The Logical Screen Descriptor Block:
. defines the logical screen
. provides information about the global color map
. provides information about image pixels
. specifies the background color
. specifies the pixel aspect ratio
--------------------------------------------------------
What is the The logical screen is the area required to contain the
logical images in a block of GIF data. The dimensions of the
screen? logical screen are specified in the Logical Screen
Descriptor Block.
Note that the logical screen may be larger than the
display surface.
--------------------------------------------------------
What is pixel Pixel aspect ratio is the ratio of a pixel's height as
aspect ratio? compared to its width, and it serves as an indication of
the pixel's shape. A pixel aspect ratio of 1.0 defines
a square pixel; a ratio of 2.0 defines a pixel which is
twice as high as it is wide.
--------------------------------------------------------
Existence The Logical Screen Descriptor Block is required. It
must immediately follow the Signature/Version Block.
--------------------------------------------------------
Size The Logical Screen Descriptor Block is seven bytes long.
--------------------------------------------------------
(continued)
GIF Revision 1.0, 5/88
11
2.2 Logical Screen Descriptor Block, continued
------------------------------------------------------------------------
------------------------------------------------------------------------
Structure of The structure of the Logical Screen Descriptor Block is
the Logical illustrated below.
Screen
Descriptor Bits
Block
7 6 5 4 3 2 1 0 Byte #
+---+---+---+---+---+---+---+---+
| | 1
+- Screen Width -+
| | 2
+-------------------------------+
| | 3
+- Screen Height -+
| | 4
+---+-----------+---+-----------+
|Map| Color Res |R1 |Pixel Size | 5
+---+-----------+---+-----------+
| Background Color Index | 6
+---+---------------------------+
|Srt| Pixel Aspect Ratio | 7
+---+---------------------------+
where:
+------------+-------+---------------------------------+
| Item | Data | Description |
| | Type | |
+------------+-------+---------------------------------+
|Screen Width|integer|width, in pixels, of the logical |
| | |screen |
| | | |
| | |Value: 1 to 65535 |
+------------+-------+---------------------------------+
|Screen |integer|height, in pixels, of the logical|
|Height | |screen |
| | | |
| | |Value: 1 to 65535 |
+------------+-------+---------------------------------+
|Map |flag |if set, a Global Color Map Block |
| | |follows the Logical Screen |
| | |Descriptor Block; otherwise, an |
| | |Extension Block or an Image |
| | |Descriptor Block follows |
+------------+-------+---------------------------------+
--------------------------------------------------------
(continued)
GIF Revision 1.0, 5/88
12
2.2 Logical Screen Descriptor Block, continued
------------------------------------------------------------------------
------------------------------------------------------------------------
Structure of +------------+-------+---------------------------------+
the Logical | Item | Data | Description |
Screen | | Type | |
Descriptor +------------+-------+---------------------------------+
Block |Color Res |field |defines the number of bits per |
(continued) | | |color component which the GIF |
| | |encoding process had available |
| | |for defining colors in the global|
| | |color map; is an indication of |
| | |the richness of the palette from |
| | |which colors in the global color |
| | |map were chosen |
| | | |
| | |Field value: 0 to 7 |
| | |Item value: 1 to 8 bits per |
| | | red, green, and blue color |
| | | component |
| | | |
| | |Number of colors in the palette: |
| | | (3 x item value) |
| | | 2 |
| | | (8 to 16,000,000+) |
+------------+-------+---------------------------------+
|R1 |n/a |reserved; must be 0 |
+------------+-------+---------------------------------+
|Pixel Size |field |number of bits in each pixel of |
| | |the images in the GIF data; |
| | |determines the number of colors |
| | |defined in the global color map |
| | |(note: does not indicate the |
| | |number of colors actually used in|
| | |an image) |
| | | |
| | |Field value: 0 to 7 |
| | |Item value: 1 to 8 bits per |
| | | pixel |
| | | |
| | |Pixel value: |
| | | (item value) |
| | | 0 to 2 - 1 |
| | | (maximum value of 255) |
| | | |
| | |Number of colors defined in the |
| | |global color map: |
| | | (item value) |
| | | 2 to 2 |
| | | (maximum value of 256) |
+------------+-------+---------------------------------+
|Background |byte |pixel for the screen background |
|Color Index | | |
+------------+-------+---------------------------------+
--------------------------------------------------------
(continued)
GIF Revision 1.0, 5/88
13
2.2 Logical Screen Descriptor Block, continued
------------------------------------------------------------------------
------------------------------------------------------------------------
Structure of +------------+-------+---------------------------------+
the Logical | Item | Data | Description |
Screen | | Type | |
Descriptor +------------+-------+---------------------------------+
Block |Srt |flag |if set, the global color map is |
(continued) | | |defined in sorted order, most |
| | |used color first; otherwise, no |
| | |assumption may be made about the |
| | |order of color definitions in the|
| | |global color map |
+------------+-------+---------------------------------+
|Pixel Aspect|field |height to width ratio of each |
|Ratio | |pixel of the source image; if 0 |
| | |no aspect ratio is specified |
| | | |
| | |Field value: 1 to 127 |
| | |Item value: |
| | | (field value + 31) / 64 |
| | |Item value range: |
| | | 32/64 to 158/64 (0.5 to 2.47) |
+------------+-------+---------------------------------+
--------------------------------------------------------
GIF Revision 1.0, 5/88
14
2.3 Global Color Map Block
------------------------------------------------------------------------
------------------------------------------------------------------------
Overview The Global Color Map Block contains the global color
map. The global color map is a series of red, green,
and blue intensity values that defines the individual
colors which may be used in an image. The global color
map is used for each image in the GIF data unless a
local color map is defined for that image.
--------------------------------------------------------
Existence The Global Color Map Block is optional. If present, it
must immediately follow the Logical Screen Descriptor
Block and the MAP flag of the Logical Screen Descriptor
Block must be set.
--------------------------------------------------------
Size The size, in bytes, of the Global Color Map Block is
three times the number of colors defined within. The
number of colors defined may range from 2 to 256 and is
determined from the number of bits per pixel:
(number of bits per pixel)
2
The number of bits per pixel is defined in the PIXEL
SIZE field of the Logical Screen Descriptor Block.
--------------------------------------------------------
Structure of The structure of the Global Color Map Block is
the Global illustrated below.
Color Map
Block Bits
7 6 5 4 3 2 1 0 Byte #
+---+---+---+---+---+---+---+---+
| Color 0 Red Intensity | 1
+-------------------------------+
| Color 0 Green Intensity | 2
+-------------------------------+
| Color 0 Blue Intensity | 3
+-------------------------------+
| Color 1 Red Intensity | 4
+-------------------------------+
| Color 1 Green Intensity | 5
+-------------------------------+
| Color 1 Blue Intensity | 6
+-------------------------------+
. . repeat, as needed,
. . for remaining colors
. .
+-------------------------------+
--------------------------------------------------------
(continued)
GIF Revision 1.0, 5/88
15
2.3 Global Color Map Block, continued
------------------------------------------------------------------------
------------------------------------------------------------------------
Structure of where:
the Global
Color Map +------------+-------+---------------------------------+
Block | Item | Data | Description |
(continued) | | Type | |
+------------+-------+---------------------------------+
|Color n |byte |indicates the amount of red |
|Red | |component color n contains |
|Intensity | | |
| | |Item value range: 0 (no red) |
| | | to 255 (maximum red) |
+------------+-------+------------------------